package com.yiren.dbaa.view.interf.impl;

import android.app.Activity;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.DashPathEffect;
import android.graphics.Matrix;
import android.graphics.Paint;
import android.graphics.Path;
import android.graphics.PathEffect;

import com.vividsolutions.jts.geom.LineString;
import com.vividsolutions.jts.geom.Polygon;
import com.yiren.backstage.currency.bean.CarStateBean;
import com.yiren.backstage.currency.bean.GpsInfoBean;
import com.yiren.backstage.currency.bean.PointBean;
import com.yiren.backstage.currency.entity.TrajectoryEntity;
import com.yiren.backstage.currency.entity.TrajectoryPointEntity;
import com.yiren.dbaa.constant.NumberConstant;
import com.yiren.dbaa.module.practice_set.map.api.IJtsJudge;
import com.yiren.dbaa.module.practice_set.map.api.impl.JtsJudgeImpl;
import com.yiren.dbaa.currency.model.TrajectVariableModel;
import com.yiren.dbaa.util.AccuracyPixelUtil;
import com.yiren.dbaa.util.JtsUtils;
import com.yiren.dbaa.view.interf.ITrajectoryDraw;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by WANGRONGXIANG
 * on 2022/4/14
 * Describe 轨迹绘制实现类
 */
public class TrajectoryDrawImpl implements ITrajectoryDraw {

    private Context context;
    private JtsUtils jtsUtils;
    private IJtsJudge iJudgeController;

    private Paint paintRXHD;      //人行横道
    private Paint paintSX;        //实线
    private Paint paintXX;        //虚线
    private Paint paintShxXx;     //双黄线中间的虚线
    private Paint paintTZX;       //停止线

    private Paint paintJtqy;      //网状线和禁停区域
    private Paint paintPoint;     //点
    private Paint paintText;      //文字
    private Paint paintCurrentPoint; //当前位置点位
    private Paint paintScale;     //地图比例
    private Paint paintLKSL;      //示例图
    private Paint paintJt;        //箭头
    private Paint paintJtLine;    //箭头实线
    private Paint paintZxq;       //中心圈
    private Paint paintScqyLine;  //刹车区域线
    private Paint paintScquArea;  //刹车区域填充

    public TrajectoryDrawImpl(Context context) {
        this.context = context;
        jtsUtils = new JtsUtils();
        iJudgeController = new JtsJudgeImpl();
        initPaint();
    }

    /**
     * 初始化画笔
     */
    private void initPaint() {
        paintSX = new Paint();
        paintSX.setColor(Color.WHITE);
        paintSX.setStyle(Paint.Style.STROKE);
        paintSX.setAntiAlias(true);

        paintXX = new Paint();
        paintXX.setStyle(Paint.Style.STROKE);
        paintXX.setColor(Color.WHITE);
        paintXX.setAntiAlias(true);

        paintShxXx = new Paint();
        paintShxXx.setStyle(Paint.Style.STROKE);
        paintShxXx.setColor(Color.WHITE);
        paintShxXx.setAntiAlias(true);
        paintShxXx.setPathEffect(new DashPathEffect(new float[]{AccuracyPixelUtil.getAccuracyScale(AccuracyPixelUtil.Accuracy_M7) * 50, AccuracyPixelUtil.getAccuracyScale(AccuracyPixelUtil.Accuracy_M7) * 50}, 0));

        paintRXHD = new Paint();
        paintRXHD.setStyle(Paint.Style.STROKE);
        paintRXHD.setAntiAlias(true);

        paintTZX = new Paint();
        paintTZX.setAntiAlias(true);

        paintScqyLine = new Paint();
        paintScqyLine.setStyle(Paint.Style.STROKE);
        paintScqyLine.setColor(Color.parseColor("#EB2828"));
        paintScqyLine.setAntiAlias(true);

        paintScquArea = new Paint();
        paintScquArea.setStyle(Paint.Style.FILL);
        paintScquArea.setAntiAlias(true);
        paintScquArea.setColor(Color.parseColor("#80FF2D2D"));

        paintJtqy = new Paint();
        paintJtqy.setColor(Color.YELLOW);
        paintJtqy.setAntiAlias(true);

        paintZxq = new Paint();
        paintZxq.setAntiAlias(true);

        paintPoint = new Paint();
        paintPoint.setColor(0xFFEEAA55);
        paintPoint.setAntiAlias(true);

        paintText = new Paint();
        paintText.setColor(0xFF555555);
        paintText.setAntiAlias(true);
        paintText.setTextSize(20);
        paintText.setTextSize(AccuracyPixelUtil.getAccuracyScale(AccuracyPixelUtil.Accuracy_M7) * 150);

        paintCurrentPoint = new Paint();
        paintCurrentPoint.setColor(0xFF33CC33);
        paintCurrentPoint.setAntiAlias(true);

        paintLKSL = new Paint();
        paintLKSL.setStyle(Paint.Style.STROKE);
        paintLKSL.setColor(Color.WHITE);
        paintLKSL.setAntiAlias(true);

        paintScale = new Paint();
        paintScale.setColor(0xFFFFFFFF);
        paintScale.setAntiAlias(true);
        paintScale.setStrokeWidth(2);
        paintScale.setTextSize(20);

        paintJt = new Paint();
        paintJt.setColor(Color.WHITE);
        paintJt.setStyle(Paint.Style.FILL);
        paintJt.setAntiAlias(true);

        paintJtLine = new Paint();
        paintJtLine.setStyle(Paint.Style.STROKE);
        paintJtLine.setColor(Color.WHITE);
        paintJtLine.setAntiAlias(true);
    }

    @Override
    public void drawCar(Canvas canvas, List<PointBean> carPoints, Bitmap bitmap, float azimuth, TrajectVariableModel model) {
        if (null != carPoints && null != carPoints.get(0) && bitmap != null && canvas != null) {
            PointBean cPoint = new PointBean((carPoints.get(1).getX() + carPoints.get(13).getX()) / 2, (carPoints.get(1).getY() + carPoints.get(13).getY()) / 2);
            PointBean lPoint = new PointBean((carPoints.get(6).getX() + carPoints.get(9).getX()) / 2, (carPoints.get(6).getY() + carPoints.get(9).getY()) / 2);
            PointBean rPoint = new PointBean((carPoints.get(17).getX() + carPoints.get(20).getX()) / 2, (carPoints.get(17).getY() + carPoints.get(20).getY()) / 2);
            float carWidth = (float) Math.sqrt((lPoint.getX() - rPoint.getX()) * (lPoint.getX() - rPoint.getX()) + (lPoint.getY() - rPoint.getY()) * (lPoint.getY() - rPoint.getY()));
            float carHeight = (float) Math.sqrt((carPoints.get(1).getX() - carPoints.get(13).getX()) * (carPoints.get(1).getX() - carPoints.get(13).getX())
                    + (carPoints.get(1).getY() - carPoints.get(13).getY()) * (carPoints.get(1).getY() - carPoints.get(13).getY()));
            float width = (443f / 170f * AccuracyPixelUtil.distanceToPixel(carWidth, model.getAccuracy()));
            float height = (1500f / 390f * AccuracyPixelUtil.distanceToPixel(carHeight, model.getAccuracy()));
            float centerX = AccuracyPixelUtil.xDistanceToPixel(cPoint.getX(), model.getOriginX(), model.getAccuracy());
            float centerY = AccuracyPixelUtil.yDistanceToPixel(cPoint.getY(), model.getOriginY(), model.getAccuracy());
            Matrix m = new Matrix();
            if (width == 0 || height == 0)
                return;
            Bitmap srcBitmap = Bitmap.createScaledBitmap(bitmap, (int) width, (int) height, true);
            m.setTranslate(centerX - width / 2, centerY - height / 2);
            m.postRotate(azimuth, centerX, centerY);
            canvas.drawBitmap(srcBitmap, m, null);
        }

    }

    @Override
    public void drawScale(Canvas canvas, TrajectVariableModel model) {
        if (canvas != null) {
            canvas.drawLine(AccuracyPixelUtil.Unit_Pixel + 20, model.getHeight() - 30, AccuracyPixelUtil.Unit_Pixel + 20, model.getHeight() - 20, paintScale);
            canvas.drawLine(AccuracyPixelUtil.Unit_Pixel + 20, model.getHeight() - 20, 20, model.getHeight() - 20, paintScale);
            canvas.drawLine(20, model.getHeight() - 20, 20, model.getHeight() - 30, paintScale);
            canvas.drawText(AccuracyPixelUtil.getAccuracyText(model.getAccuracy()), AccuracyPixelUtil.Unit_Pixel / 2 + 5, model.getHeight() - 28, paintScale);
        }
    }

    @Override
    public void drawCurrentPoint(Canvas canvas, GpsInfoBean gpsInfo, PointBean currentPoint, TrajectVariableModel model) {
        if (canvas != null) {
            if (gpsInfo != null) {
                canvas.drawCircle(model.getOriginX() + AccuracyPixelUtil.distanceToPixel(currentPoint.getX(), model.getAccuracy()), model.getOriginY() - AccuracyPixelUtil.distanceToPixel(currentPoint.getY(), model.getAccuracy()), 10, paintCurrentPoint);
            } else {
                canvas.drawCircle(model.getOriginX(), model.getOriginY(), 10, paintCurrentPoint);
            }
        }
    }

    @Override
    public void drawCollectSx(Canvas canvas, List<TrajectoryPointEntity> points, TrajectVariableModel model, int bmId) {
        if (null != canvas && null != points && points.size() > 0) {
            boolean isCurrentTrajectory = isCurrentTrajectory(points, model, paintSX);
            LineString shiLine = jtsUtils.createLineByPoints(points);
            if (null != shiLine && null != model.getCarLineString() && null != model.getWheelLineString()) {
                if (jtsUtils.intersects(shiLine, model.getCarLineString()) || jtsUtils.intersects(shiLine, model.getWheelLineString())) {
                    paintSX.setColor(Color.RED);
                }
            }
            Path path = new Path();
            for (int i = 0; i < points.size(); i++) {
                if (i == 0) {
                    path.moveTo(AccuracyPixelUtil.xDistanceToPixel(points.get(i).getPoint().getX(), model.getOriginX(), model.getAccuracy()), AccuracyPixelUtil.yDistanceToPixel(points.get(i).getPoint().getY(), model.getOriginY(), model.getAccuracy()));
                } else {
                    path.lineTo(AccuracyPixelUtil.xDistanceToPixel(points.get(i).getPoint().getX(), model.getOriginX(), model.getAccuracy()), AccuracyPixelUtil.yDistanceToPixel(points.get(i).getPoint().getY(), model.getOriginY(), model.getAccuracy()));
                }
            }
            canvas.drawPath(path, paintSX);
            for (int i = 0; i < points.size(); i++) {  //画点
                drawPoint(canvas, points.get(i), bmId, (i + 1), isCurrentTrajectory, model);
            }
        }
    }

    @Override
    public void drawCollectXx(Canvas canvas, List<TrajectoryPointEntity> points, TrajectVariableModel model, int bmId) {
        paintXX.setPathEffect(new DashPathEffect(new float[]{AccuracyPixelUtil.getAccuracyScale(model.getAccuracy()) * 200, AccuracyPixelUtil.getAccuracyScale(model.getAccuracy()) * 400}, 0));
        if (null != canvas && null != points && points.size() > 0) {
            boolean isCurrentTrajectory = isCurrentTrajectory(points, model, paintXX);
            Path path = new Path();
            for (int i = 0; i < points.size(); i++) {
                PointBean point = points.get(i).getPoint();
                if (i < points.size() - 1) {
                    PointBean lastPoint = points.get(i + 1).getPoint();
                    path.moveTo(AccuracyPixelUtil.xDistanceToPixel(point.getX(), model.getOriginX(), model.getAccuracy()), AccuracyPixelUtil.yDistanceToPixel(point.getY(), model.getOriginY(), model.getAccuracy()));
                    path.lineTo(AccuracyPixelUtil.xDistanceToPixel(lastPoint.getX(), model.getOriginX(), model.getAccuracy()), AccuracyPixelUtil.yDistanceToPixel(lastPoint.getY(), model.getOriginY(), model.getAccuracy()));
                }
            }
            canvas.drawPath(path, paintXX);
            for (int i = 0; i < points.size(); i++) {  //画点
                drawPoint(canvas, points.get(i), bmId, (i + 1), isCurrentTrajectory, model);
            }
        }
    }

    @Override
    public void drawCollectRXHD(Canvas canvas, List<TrajectoryPointEntity> points, TrajectVariableModel model, int bmId) {
        if (model.isCollect()) {
            if (null != canvas) {
                float startX = 0;
                float endX = 0;
                float startY = 0;
                float endY = 0;
                float lineDistance = (float) (model.getHeight() * 0.05);
                int lineCount = 0;
                paintRXHD.setColor(Color.WHITE);
                paintRXHD.setStrokeWidth(lineDistance / 2);
                paintRXHD.setPathEffect(null);
                startX = (float) (model.getWidth() * 0.818);
                endX = (float) (model.getWidth() * 0.935);
                startY = (float) (model.getHeight() * 0.304);
                endY = (float) (model.getHeight() - model.getHeight() * 0.185 - (model.getHeight() - model.getHeight() * 0.185 - startY) % lineDistance);
                lineCount = (int) ((endY - startY) / lineDistance);
                for (int i = 0; i < lineCount; i++) {
                    canvas.drawLine(startX, startY + i * lineDistance, endX, startY + i * lineDistance, paintRXHD);
                    if (i == 0) {
                        drawGdPoint(canvas, model.getWidth(), startX, startY - lineDistance * (1.0f / 4.0f), "4", paintPoint, paintText);
                        drawGdPoint(canvas, model.getWidth(), endX, startY - lineDistance * (1.0f / 4.0f), "3", paintPoint, paintText);
                    } else if (i == lineCount - 1) {
                        drawGdPoint(canvas, model.getWidth(), startX, endY - lineDistance * (3.0f / 4.0f), "1", paintPoint, paintText);
                        drawGdPoint(canvas, model.getWidth(), endX, endY - lineDistance * (3.0f / 4.0f), "2", paintPoint, paintText);
                    }
                }
            }
        } else {
            if (null != points && points.size() > 3) {
                boolean isCurrentTrajectory = isCurrentTrajectory(points, model, paintRXHD);
                //检测车辆是否停在人行横道
                PointBean onePoint = points.get(0).getPoint();
                PointBean twoPoint = points.get(1).getPoint();
                PointBean threePoint = points.get(2).getPoint();
                PointBean fourPoint = points.get(3).getPoint();
                if (null != model.getCarLineString() && null != model.getWheelLineString()) {
                    boolean isTop = CarStateBean.getInstance().getSpeed() <= NumberConstant.CAR_STOP_SPEED && (jtsUtils.intersects(jtsUtils.createPolygonByPoints(points), model.getCarLineString()) || jtsUtils.intersects(jtsUtils.createPolygonByPoints(points), model.getWheelLineString()));
                    if (isTop) paintRXHD.setColor(Color.RED);
                }
                if (null != canvas) {
                    //根据两点之间得出中间点  画虚线
                    PointBean cPoint1 = new PointBean((onePoint.getX() + twoPoint.getX()) / 2, (onePoint.getY() + twoPoint.getY()) / 2);
                    PointBean cPoint2 = new PointBean((threePoint.getX() + fourPoint.getX()) / 2, (threePoint.getY() + fourPoint.getY()) / 2);
                    //设置线间隔
                    PathEffect effects = new DashPathEffect(new float[]{AccuracyPixelUtil.getAccuracyScale(model.getAccuracy()) * points.get(0).getTrajectory().getLineWidth(), AccuracyPixelUtil.getAccuracyScale(model.getAccuracy()) * points.get(0).getTrajectory().getLineWidth()}, 0);
                    paintRXHD.setPathEffect(effects);
                    Path path = new Path();
                    path.moveTo(model.getOriginX() + AccuracyPixelUtil.distanceToPixel(cPoint1.getX(), model.getAccuracy()), model.getOriginY() - AccuracyPixelUtil.distanceToPixel(cPoint1.getY(), model.getAccuracy()));
                    path.lineTo(model.getOriginX() + AccuracyPixelUtil.distanceToPixel(cPoint2.getX(), model.getAccuracy()), model.getOriginY() - AccuracyPixelUtil.distanceToPixel(cPoint2.getY(), model.getAccuracy()));
                    //设置虚线宽度
                    double distance = Math.sqrt(Math.pow(((model.getOriginX() + AccuracyPixelUtil.distanceToPixel(onePoint.getX(), model.getAccuracy())) - (model.getOriginX() + AccuracyPixelUtil.distanceToPixel(twoPoint.getX(), model.getAccuracy()))), 2) + Math.pow(((model.getOriginY() - AccuracyPixelUtil.distanceToPixel(onePoint.getY(), model.getAccuracy())) - (model.getOriginY() - AccuracyPixelUtil.distanceToPixel(twoPoint.getY(), model.getAccuracy()))), 2));
                    paintRXHD.setStrokeWidth((float) distance);
                    canvas.drawPath(path, paintRXHD);
                    for (int i = 0; i < points.size(); i++) { //画点
                        drawPoint(canvas, points.get(i), bmId, i + 1, isCurrentTrajectory, model);
                    }
                }
            }
        }
    }

    @Override
    public void drawCollectTZX(Canvas canvas, List<TrajectoryPointEntity> points, TrajectVariableModel model, int bmId) {
        if (model.isCollect()) {
            if (null != canvas) {
                float startX = (float) (model.getWidth() * 0.883);
                float startY = (float) (model.getHeight() * 0.287);
                float endY = (float) (model.getHeight() * 0.764);
                paintTZX.setColor(Color.WHITE);
                paintTZX.setStrokeWidth((float) (model.getWidth() * 0.052));
                canvas.drawLine(startX, startY, startX, endY, paintTZX);
                drawGdPoint(canvas, model.getWidth(), startX, startY, "2", paintPoint, paintText);
                drawGdPoint(canvas, model.getWidth(), startX, endY, "1", paintPoint, paintText);
            }
        } else {
            if (null != points && points.size() == 2) {
                boolean isCurrentTrajectory = isCurrentTrajectory(points, model, paintTZX);
                PointBean onePoint = points.get(0).getPoint();
                PointBean twoPoint = points.get(1).getPoint();
                //检测车辆是否停在停止线
                if (CarStateBean.getInstance().getSpeed() <= NumberConstant.CAR_STOP_SPEED && null != model.getCarLineString() && null != model.getWheelLineString()) {
                    boolean isTop = jtsUtils.intersects(jtsUtils.createLineByPoints(points), model.getCarLineString()) || jtsUtils.intersects(jtsUtils.createLineByPoints(points), model.getWheelLineString());
                    if (isTop) paintTZX.setColor(Color.RED);
                }
                if (null != canvas) {
                    canvas.drawLine(AccuracyPixelUtil.xDistanceToPixel(onePoint.getX(), model.getOriginX(), model.getAccuracy()), AccuracyPixelUtil.yDistanceToPixel(onePoint.getY(), model.getOriginY(), model.getAccuracy()), AccuracyPixelUtil.xDistanceToPixel(twoPoint.getX(), model.getOriginX(), model.getAccuracy()), AccuracyPixelUtil.yDistanceToPixel(twoPoint.getY(), model.getOriginY(), model.getAccuracy()), paintTZX);
                    //画点
                    for (int i = 0; i < points.size(); i++) {
                        drawPoint(canvas, points.get(i), bmId, i + 1, isCurrentTrajectory, model);
                    }
                }
            }
        }
    }

    @Override
    public void drawCollectJtqy(Canvas canvas, List<TrajectoryPointEntity> points, TrajectVariableModel model, int bmId) {
        if (null != points && points.size() > 3) {
            boolean isCurrentTrajectory = isCurrentTrajectory(points, model, paintJtqy);
            if (!model.isCollect() && null != model.getCarLineString() && null != model.getWheelLineString()) {
                boolean isTop = CarStateBean.getInstance().getSpeed() <= NumberConstant.CAR_STOP_SPEED && (jtsUtils.intersects(jtsUtils.createPolygonByPoints(points), model.getCarLineString()) || jtsUtils.intersects(jtsUtils.createPolygonByPoints(points), model.getWheelLineString()));
                if (isTop) paintJtqy.setColor(Color.RED);
            }
            if (null != canvas) {
                Path path = new Path();
                for (int i = 0; i < points.size(); i++) {
                    if (i == 0) {
                        path.moveTo(AccuracyPixelUtil.xDistanceToPixel(points.get(i).getPoint().getX(), model.getOriginX(), model.getAccuracy()), AccuracyPixelUtil.yDistanceToPixel(points.get(i).getPoint().getY(), model.getOriginY(), model.getAccuracy()));
                    } else {
                        path.lineTo(AccuracyPixelUtil.xDistanceToPixel(points.get(i).getPoint().getX(), model.getOriginX(), model.getAccuracy()), AccuracyPixelUtil.yDistanceToPixel(points.get(i).getPoint().getY(), model.getOriginY(), model.getAccuracy()));
                    }
                }
                path.close();
                canvas.drawPath(path, paintJtqy);
                for (int i = 0; i < points.size(); i++) { //画点
                    drawPoint(canvas, points.get(i), bmId, (i + 1), isCurrentTrajectory, model);
                }
//                if (!isCollect) {
//                    if (points.size() > 2) {
//                        drawWebLine(canvas, points);
//                    }
//                }
            }
        }
    }

    @Override
    public void drawCollectWebLine(Canvas canvas, List<TrajectoryPointEntity> points, TrajectVariableModel model) {
        PointBean point1 = points.get(0).getPoint();
        PointBean point2 = points.get(1).getPoint();
        double tanq = (point2.getY() - point1.getY()) / (point2.getX() - point1.getX());
        //获取网状线第一条边的长度
        double distance = Math.sqrt((point2.getX() - point1.getX()) * (point2.getX() - point1.getX()) + (point2.getY() - point1.getY()) * (point2.getY() - point1.getY()));
        //4米画一条线，左右各多画10条线
        for (int i = -10; i < distance / 4 + 10; i++) {
            //4+0.01 0.01防止首位点位重合
            PointBean point = new PointBean((float) (point1.getX() + 4.01 * i / distance * (point2.getX() - point1.getX())), (float) (point1.getY() + 4.01 * i / distance * (point2.getY() - point1.getY())));
            //获取当前线段旋转40度的线段
            PointBean[] lines = jtsUtils.getRotateDegreeLine(point, tanq, 40, 100);
            caculateIntersectPoint(canvas, points, lines, model);
            //获取当前线段旋转140度的线段
            PointBean[] lines2 = jtsUtils.getRotateDegreeLine(point, tanq, 140, 100);
            caculateIntersectPoint(canvas, points, lines2, model);
        }
    }

    @Override
    public void drawCollectScqy(Canvas canvas, List<TrajectoryPointEntity> points, TrajectVariableModel model, int bmId) {
        if (null != points && points.size() > 0) {
            paintScqyLine.setPathEffect(new DashPathEffect(new float[]{AccuracyPixelUtil.getAccuracyScale(model.getAccuracy()) * 50, AccuracyPixelUtil.getAccuracyScale(model.getAccuracy()) * 50}, 0));
            boolean isCurrentTrajectory = isCurrentTrajectory(points, model, paintScqyLine);
            if (null != canvas) {
                Path path = new Path();
                for (int i = 0; i < points.size(); i++) {
                    PointBean point = points.get(i).getPoint();
                    if (i == 0) {
                        path.moveTo(AccuracyPixelUtil.xDistanceToPixel(point.getX(), model.getOriginX(), model.getAccuracy()), AccuracyPixelUtil.yDistanceToPixel(point.getY(), model.getOriginY(), model.getAccuracy()));
                    } else {
                        path.lineTo(AccuracyPixelUtil.xDistanceToPixel(point.getX(), model.getOriginX(), model.getAccuracy()), AccuracyPixelUtil.yDistanceToPixel(point.getY(), model.getOriginY(), model.getAccuracy()));
                    }
                }
                if (points.size() == 4) {
                    path.close();
                    canvas.drawPath(path, paintScquArea);
                }
                canvas.drawPath(path, paintScqyLine);
                for (int i = 0; i < points.size(); i++) {  //画点
                    drawPoint(canvas, points.get(i), bmId, (i + 1), isCurrentTrajectory, model);
                }
            }
        }
    }

    @Override
    public void drawCollectZxq(Canvas canvas, List<TrajectoryPointEntity> points, TrajectVariableModel model, List<PointBean> carPoints, int bmId) {
        if (model.isCollect()) {
            if (null != canvas) {
                float centerX = (float) (model.getWidth() * 0.87);
                float radius = (float) (model.getWidth() * 0.078);
                paintZxq.setColor(Color.WHITE);
                canvas.drawCircle(centerX, model.getHeight() / 2, radius, paintZxq);
                drawGdPoint(canvas, model.getWidth(), centerX, model.getHeight() / 2, "1", paintPoint, paintText);
                drawGdPoint(canvas, model.getWidth(), centerX, model.getHeight() / 2 + radius, "2", paintPoint, paintText);
            }
        } else {
            if (null != points && points.size() > 1) {
                boolean isCurrentTrajectory = isCurrentTrajectory(points, model, paintZxq);
                PointBean onePoint = points.get(0).getPoint();
                PointBean twoPoint = points.get(1).getPoint();
                //计算两点距离
                float radius = (float) Math.sqrt(Math.abs((onePoint.getX() - twoPoint.getX()) * (onePoint.getX() - twoPoint.getX()) + (onePoint.getY() - twoPoint.getY()) * (onePoint.getY() - twoPoint.getY())));
                //检测是否压中心圈
                if (null != model.getCarLineString()) {
                    iJudgeController.checkZxqLeftTurn(onePoint.getX(), onePoint.getY(), radius, model.getCarLineString(), carPoints);
                    Polygon zxq = jtsUtils.createCircle(onePoint.getX(), onePoint.getY(), radius);
                    if (null != zxq && null != model.getWheelLineString()) {
                        if (jtsUtils.intersects(zxq, model.getCarLineString()) || jtsUtils.intersects(zxq, model.getWheelLineString())) {
                            paintZxq.setColor(Color.RED);
                        }
                    }
                }
                if (null != canvas) {
                    //画圆
                    canvas.drawCircle(AccuracyPixelUtil.xDistanceToPixel(onePoint.getX(), model.getOriginX(), model.getAccuracy()), AccuracyPixelUtil.yDistanceToPixel(onePoint.getY(), model.getOriginY(), model.getAccuracy()), AccuracyPixelUtil.getAccuracyScale(model.getAccuracy()) * (radius * 100), paintZxq);
                    for (int i = 0; i < points.size(); i++) { //画点
                        drawPoint(canvas, points.get(i), bmId, i + 1, isCurrentTrajectory, model);
                    }
                }
            }
        }
    }

    @Override
    public void drawCollectShx(Canvas canvas, List<TrajectoryPointEntity> points, TrajectVariableModel model, int shxLineType, int bmId) {
        if (null != canvas && null != points && points.size() > 0) {
            boolean isCurrentTrajectory = isCurrentTrajectory(points, model, paintSX);
            isCurrentTrajectory(points, model, paintShxXx);
            for (int i = 0; i < points.size(); i++) {
                TrajectoryPointEntity tPoint = points.get(i);
                String currentHeadValue = tPoint.getOrderIndex().substring(0, 1);
                if (i < points.size() - 1) {
                    TrajectoryPointEntity nextTp = points.get(i + 1);
                    String nextHeadValue = nextTp.getOrderIndex().substring(0, 1);
                    //索引第一个值跟上次值不同时
                    if (shxLineType == 1) {
                        if (nextHeadValue.equals(currentHeadValue)) {
                            canvas.drawLine(AccuracyPixelUtil.xDistanceToPixel(tPoint.getPoint().getX(), model.getOriginX(), model.getAccuracy()), AccuracyPixelUtil.yDistanceToPixel(tPoint.getPoint().getY(), model.getOriginY(), model.getAccuracy()), AccuracyPixelUtil.xDistanceToPixel(nextTp.getPoint().getX(), model.getOriginX(), model.getAccuracy()), AccuracyPixelUtil.yDistanceToPixel(nextTp.getPoint().getY(), model.getOriginY(), model.getAccuracy()), paintSX);
                        }
                    } else if (shxLineType == 2) {
                        if (nextHeadValue.equals(currentHeadValue)) {
                            canvas.drawLine(AccuracyPixelUtil.xDistanceToPixel(tPoint.getPoint().getX(), model.getOriginX(), model.getAccuracy()), AccuracyPixelUtil.yDistanceToPixel(tPoint.getPoint().getY(), model.getOriginY(), model.getAccuracy()), AccuracyPixelUtil.xDistanceToPixel(nextTp.getPoint().getX(), model.getOriginX(), model.getAccuracy()), AccuracyPixelUtil.yDistanceToPixel(nextTp.getPoint().getY(), model.getOriginY(), model.getAccuracy()), paintShxXx);
                        }
                    } else {
                        if (nextHeadValue.equals(currentHeadValue)) {
                            if (currentHeadValue.equals("1")) {
                                canvas.drawLine(AccuracyPixelUtil.xDistanceToPixel(tPoint.getPoint().getX(), model.getOriginX(), model.getAccuracy()), AccuracyPixelUtil.yDistanceToPixel(tPoint.getPoint().getY(), model.getOriginY(), model.getAccuracy()), AccuracyPixelUtil.xDistanceToPixel(nextTp.getPoint().getX(), model.getOriginX(), model.getAccuracy()), AccuracyPixelUtil.yDistanceToPixel(nextTp.getPoint().getY(), model.getOriginY(), model.getAccuracy()), paintShxXx);
                            } else if (currentHeadValue.equals("2")) {
                                canvas.drawLine(AccuracyPixelUtil.xDistanceToPixel(tPoint.getPoint().getX(), model.getOriginX(), model.getAccuracy()), AccuracyPixelUtil.yDistanceToPixel(tPoint.getPoint().getY(), model.getOriginY(), model.getAccuracy()), AccuracyPixelUtil.xDistanceToPixel(nextTp.getPoint().getX(), model.getOriginX(), model.getAccuracy()), AccuracyPixelUtil.yDistanceToPixel(nextTp.getPoint().getY(), model.getOriginY(), model.getAccuracy()), paintSX);
                            }
                        }
                    }
                }
                //画点
                drawPoint(canvas, points.get(i), bmId, (i + 1), isCurrentTrajectory, model);
            }
        }
    }

    @Override
    public void drawCollectLkZX(Canvas canvas, List<TrajectoryPointEntity> points, TrajectVariableModel model, int bmId) {
        if (model.isCollect()) {
//            if (collectType == 10) drawSampleZX(canvas);
        } else {
            if (null != points && points.size() > 1) {
                boolean isCurrentTrajectory = isCurrentTrajectory(points, model, paintJtLine);
                TrajectoryEntity trajectory = points.get(0).getTrajectory();
                PointBean onePoint = points.get(0).getPoint();
                PointBean twoPoint = points.get(1).getPoint();
                if (null != canvas) {
                    canvas.drawLine(AccuracyPixelUtil.xDistanceToPixel(onePoint.getX(), model.getOriginX(), model.getAccuracy()), AccuracyPixelUtil.yDistanceToPixel(onePoint.getY(), model.getOriginY(), model.getAccuracy()), AccuracyPixelUtil.xDistanceToPixel(twoPoint.getX(), model.getOriginX(), model.getAccuracy()), AccuracyPixelUtil.yDistanceToPixel(twoPoint.getY(), model.getOriginY(), model.getAccuracy()), paintJtLine);
                    float bottom = (float) (trajectory.getLineWidth() / 100 + 0.5);
                    drawJt(canvas, onePoint, twoPoint, bottom * 2, bottom, model);
                    //画点
                    for (int i = 0; i < points.size(); i++) {
                        drawPoint(canvas, points.get(i), bmId, i + 1, isCurrentTrajectory, model);
                    }
                }
            }
        }
    }

    @Override
    public void drawCollectLkYZ(Canvas canvas, List<TrajectoryPointEntity> points, TrajectVariableModel model, int bmId) {
        if (model.isCollect()) {
//            drawSampleYZ(canvas);
        } else {
            if (null != points && points.size() > 1) {
                boolean isCurrentTrajectory = isCurrentTrajectory(points, model, paintJtLine);
                TrajectoryEntity trajectory = points.get(0).getTrajectory();
                PointBean onePoint = points.get(0).getPoint();
                PointBean twoPoint = points.get(1).getPoint();
                if (null != canvas) {
                    canvas.drawLine(AccuracyPixelUtil.xDistanceToPixel(onePoint.getX(), model.getOriginX(), model.getAccuracy()), AccuracyPixelUtil.yDistanceToPixel(onePoint.getY(), model.getOriginY(), model.getAccuracy()), AccuracyPixelUtil.xDistanceToPixel(twoPoint.getX(), model.getOriginX(), model.getAccuracy()), AccuracyPixelUtil.yDistanceToPixel(twoPoint.getY(), model.getOriginY(), model.getAccuracy()), paintJtLine);
                    onePoint = returnZxzjPoint(twoPoint, onePoint, 0.01, false);
                    PointBean threePoint = jtThreePoint(twoPoint, onePoint, 40, -90);
                    if (null != threePoint) {
                        canvas.drawLine(AccuracyPixelUtil.xDistanceToPixel(twoPoint.getX(), model.getOriginX(), model.getAccuracy()), AccuracyPixelUtil.yDistanceToPixel(twoPoint.getY(), model.getOriginY(), model.getAccuracy()), AccuracyPixelUtil.xDistanceToPixel(threePoint.getX(), model.getOriginX(), model.getAccuracy()), AccuracyPixelUtil.yDistanceToPixel(threePoint.getY(), model.getOriginY(), model.getAccuracy()), paintJtLine);
                        float bottom = (float) (trajectory.getLineWidth() / 100 + 0.6);
                        drawJt(canvas, twoPoint, threePoint, bottom, bottom, model);
                    }
                    for (int i = 0; i < points.size(); i++) {  //画点
                        drawPoint(canvas, points.get(i), bmId, i + 1, isCurrentTrajectory, model);
                    }
                }
            }
        }
    }

    @Override
    public void drawCollectLkZZ(Canvas canvas, List<TrajectoryPointEntity> points, TrajectVariableModel model, int bmId) {
        if (model.isCollect()) {
//            if (collectType == 12) drawSampleZZ(canvas);
        } else {
            if (null != points && points.size() > 1) {
                boolean isCurrentTrajectory = isCurrentTrajectory(points, model, paintJtLine);
                TrajectoryEntity trajectory = points.get(0).getTrajectory();
                PointBean onePoint = points.get(0).getPoint();
                PointBean twoPoint = points.get(1).getPoint();
                if (null != canvas) {
                    canvas.drawLine(AccuracyPixelUtil.xDistanceToPixel(onePoint.getX(), model.getOriginX(), model.getAccuracy()), AccuracyPixelUtil.yDistanceToPixel(onePoint.getY(), model.getOriginY(), model.getAccuracy()), AccuracyPixelUtil.xDistanceToPixel(twoPoint.getX(), model.getOriginX(), model.getAccuracy()), AccuracyPixelUtil.yDistanceToPixel(twoPoint.getY(), model.getOriginY(), model.getAccuracy()), paintJtLine);
                    onePoint = returnZxzjPoint(twoPoint, onePoint, 0.01, false);
                    PointBean threePoint = jtThreePoint(twoPoint, onePoint, 40, 90);
                    if (null != threePoint) {
                        canvas.drawLine(AccuracyPixelUtil.xDistanceToPixel(twoPoint.getX(), model.getOriginX(), model.getAccuracy()), AccuracyPixelUtil.yDistanceToPixel(twoPoint.getY(), model.getOriginY(), model.getAccuracy()), AccuracyPixelUtil.xDistanceToPixel(threePoint.getX(), model.getOriginX(), model.getAccuracy()), AccuracyPixelUtil.yDistanceToPixel(threePoint.getY(), model.getOriginY(), model.getAccuracy()), paintJtLine);
                        float bottom = (float) (trajectory.getLineWidth() / 100 + 0.6);
                        drawJt(canvas, twoPoint, threePoint, bottom, bottom, model);
                    }
                    for (int i = 0; i < points.size(); i++) { //画点
                        drawPoint(canvas, points.get(i), bmId, i + 1, isCurrentTrajectory, model);
                    }
                }
            }
        }
    }

    @Override
    public void drawCollectLkDT(Canvas canvas, List<TrajectoryPointEntity> points, TrajectVariableModel model, int bmId) {
        if (model.isCollect()) {
//            if (collectType == 13) drawSampleDT(canvas);
        } else {
            if (null != points && points.size() > 1) {
                boolean isCurrentTrajectory = isCurrentTrajectory(points, model, paintJtLine);
                TrajectoryEntity trajectory = points.get(0).getTrajectory();
                PointBean onePoint = points.get(0).getPoint();
                PointBean twoPoint = points.get(1).getPoint();
                if (null != canvas) {
                    PointBean threePoint = jtThreePoint(onePoint, twoPoint, 0, -100);
                    PointBean fourPoint = returnZxzjPoint(twoPoint, onePoint, 0.3, true);
                    fourPoint = jtThreePoint(onePoint, fourPoint, 0, -100);
                    Path path = new Path();
                    path.moveTo(AccuracyPixelUtil.xDistanceToPixel(onePoint.getX(), model.getOriginX(), model.getAccuracy()), AccuracyPixelUtil.yDistanceToPixel(onePoint.getY(), model.getOriginY(), model.getAccuracy()));
                    path.lineTo(AccuracyPixelUtil.xDistanceToPixel(twoPoint.getX(), model.getOriginX(), model.getAccuracy()), AccuracyPixelUtil.yDistanceToPixel(twoPoint.getY(), model.getOriginY(), model.getAccuracy()));
                    path.quadTo(AccuracyPixelUtil.xDistanceToPixel(threePoint.getX(), model.getOriginX(), model.getAccuracy()), AccuracyPixelUtil.yDistanceToPixel(threePoint.getY(), model.getOriginY(), model.getAccuracy()), AccuracyPixelUtil.xDistanceToPixel(fourPoint.getX(), model.getOriginX(), model.getAccuracy()), AccuracyPixelUtil.yDistanceToPixel(fourPoint.getY(), model.getOriginY(), model.getAccuracy()));
                    canvas.drawPath(path, paintJtLine);
                    float bottom = (float) (trajectory.getLineWidth() / 100 + 0.5);
                    drawJt(canvas, threePoint, fourPoint, bottom * 2, bottom, model);
                    for (int i = 0; i < points.size(); i++) { //画点
                        drawPoint(canvas, points.get(i), bmId, i + 1, isCurrentTrajectory, model);
                    }
                }
            }
        }
    }

    @Override
    public void drawCollectLkZXZZ(Canvas canvas, List<TrajectoryPointEntity> points, TrajectVariableModel model, int bmId) {
        if (model.isCollect()) {
//            drawSampleZXZZ(canvas);
        } else {
            if (null != canvas && null != points && points.size() > 1) {
                TrajectoryEntity trajectory = points.get(0).getTrajectory();
                PointBean onePoint = points.get(0).getPoint();
                PointBean twoPoint = points.get(1).getPoint();
                onePoint = returnZxzjPoint(twoPoint, onePoint, 0.5, true);
                PointBean threePoint = jtThreePoint(twoPoint, onePoint, 60, 90);
                if (null != threePoint) {
                    paintJtLine.setStrokeWidth(AccuracyPixelUtil.getAccuracyScale(model.getAccuracy()) * trajectory.getLineWidth() * 2);
                    canvas.drawLine(AccuracyPixelUtil.xDistanceToPixel(onePoint.getX(), model.getOriginX(), model.getAccuracy()), AccuracyPixelUtil.yDistanceToPixel(onePoint.getY(), model.getOriginY(), model.getAccuracy()), AccuracyPixelUtil.xDistanceToPixel(threePoint.getX(), model.getOriginX(), model.getAccuracy()), AccuracyPixelUtil.yDistanceToPixel(threePoint.getY(), model.getOriginY(), model.getAccuracy()), paintJtLine);
                    float bottom = (float) (trajectory.getLineWidth() / 100 + 0.6);
                    drawJt(canvas, onePoint, threePoint, bottom, bottom, model);
                }
                drawCollectLkZX(canvas, points, model, bmId);
            }
        }
    }

    @Override
    public void drawCollectLkZXYZ(Canvas canvas, List<TrajectoryPointEntity> points, TrajectVariableModel model, int bmId) {
        if (model.isCollect()) {
//            drawSampleZXYZ(canvas);
        } else {
            if (null != canvas && null != points && points.size() > 1) {
                TrajectoryEntity trajectory = points.get(0).getTrajectory();
                PointBean onePoint = points.get(0).getPoint();
                PointBean twoPoint = points.get(1).getPoint();
                onePoint = returnZxzjPoint(twoPoint, onePoint, 0.5, true);
                PointBean threePoint = jtThreePoint(twoPoint, onePoint, 60, -90);
                if (null != threePoint) {
                    paintJtLine.setStrokeWidth(AccuracyPixelUtil.getAccuracyScale(model.getAccuracy()) * trajectory.getLineWidth() * 2);
                    canvas.drawLine(AccuracyPixelUtil.xDistanceToPixel(onePoint.getX(), model.getOriginX(), model.getAccuracy()), AccuracyPixelUtil.yDistanceToPixel(onePoint.getY(), model.getOriginY(), model.getAccuracy()), AccuracyPixelUtil.xDistanceToPixel(threePoint.getX(), model.getOriginX(), model.getAccuracy()), AccuracyPixelUtil.yDistanceToPixel(threePoint.getY(), model.getOriginY(), model.getAccuracy()), paintJtLine);
                    float bottom = (float) (trajectory.getLineWidth() / 100 + 0.6);
                    drawJt(canvas, onePoint, threePoint, bottom, bottom, model);
                }
                drawCollectLkZX(canvas, points, model, bmId);
            }
        }
    }

    @Override
    public void drawCollectLkZXDT(Canvas canvas, List<TrajectoryPointEntity> points, TrajectVariableModel model, int bmId) {
        if (model.isCollect()) {
//            if (collectType == 16) drawSampleDTZX(canvas);
        } else {
            drawCollectLkZX(canvas, points, model, bmId);
            drawCollectLkDT(canvas, points, model, bmId);
        }
    }

    @Override
    public void drawCollectLkZZDT(Canvas canvas, List<TrajectoryPointEntity> points, TrajectVariableModel model, int bmId) {
        if (model.isCollect()) {
//            drawSampleDTZZ(canvas);
        } else {
            if (null != canvas && null != points && points.size() > 1) {
                TrajectoryEntity trajectory = points.get(0).getTrajectory();
                PointBean twoPoint = points.get(1).getPoint();
                PointBean onePoint = returnZxzjPoint(twoPoint, points.get(0).getPoint(), 0.01, false);
                PointBean threePoint = jtThreePoint(twoPoint, onePoint, 40, 90);
                if (null != threePoint) {
                    canvas.drawLine(AccuracyPixelUtil.xDistanceToPixel(twoPoint.getX(), model.getOriginX(), model.getAccuracy()), AccuracyPixelUtil.yDistanceToPixel(twoPoint.getY(), model.getOriginY(), model.getAccuracy()), AccuracyPixelUtil.xDistanceToPixel(threePoint.getX(), model.getOriginX(), model.getAccuracy()), AccuracyPixelUtil.yDistanceToPixel(threePoint.getY(), model.getOriginY(), model.getAccuracy()), paintJtLine);
                    float bottom = (float) (trajectory.getLineWidth() / 100 + 0.6);
                    drawJt(canvas, twoPoint, threePoint, bottom, bottom, model);
                    drawCollectLkDT(canvas, points, model, bmId);
                }
            }
        }
    }

    @Override
    public void drawCollectLkZXZZDT(Canvas canvas, List<TrajectoryPointEntity> points, TrajectVariableModel model, int bmId) {
        if (model.isCollect()) {
//            drawSampleDTZXZZ(canvas);
        } else {
            if (null != canvas && null != points && points.size() > 1) {
                drawCollectLkZX(canvas, points, model, bmId);
                drawCollectLkDT(canvas, points, model, bmId);
                drawCollectLkZZ(canvas, points, model, bmId);
            }
        }
    }

    @Override
    public void drawCollectLkZYZ(Canvas canvas, List<TrajectoryPointEntity> points, TrajectVariableModel model, int bmId) {
        if (model.isCollect()) {
//            drawSampleDTZXZZ(canvas);
        } else {
            if (null != canvas && null != points && points.size() > 1) {
                drawCollectLkZZ(canvas, points, model, bmId);
                drawCollectLkYZ(canvas, points, model, bmId);
            }
        }
    }

    @Override
    public void drawSampleZXQ(Canvas canvas, TrajectVariableModel model) {
        if (null != canvas) {
            float centerX = (float) (model.getWidth() * 0.87);
            float radius = (float) (model.getWidth() * 0.078);
            paintZxq.setColor(Color.WHITE);
            canvas.drawCircle(centerX, model.getHeight() / 2, radius, paintZxq);
            drawGdPoint(canvas, model.getWidth(), centerX, model.getHeight() / 2, "1", paintPoint, paintText);
            drawGdPoint(canvas, model.getWidth(), centerX, model.getHeight() / 2 + radius, "2", paintPoint, paintText);
        }
    }

    @Override
    public void drawSampleLkZX(Canvas canvas, TrajectVariableModel model) {
        if (null != canvas) {
            float startX = (float) (model.getWidth() * 0.87);
            float startY = (float) (model.getHeight() * 0.73);
            float endY = (float) (model.getHeight() * 0.4);
            paintLKSL.setStrokeWidth((float) (model.getWidth() * 0.053));
            canvas.drawLine(startX, startY, startX, endY, paintLKSL);
            drawArrow(canvas, startX - (float) (model.getWidth() * 0.065), endY, startX + (float) (model.getWidth() * 0.065), endY, startX, endY - (float) (model.getWidth() * 0.052), paintJt);
            drawGdPoint(canvas, model.getWidth(), startX, startY, "1", paintPoint, paintText);
            drawGdPoint(canvas, model.getWidth(), startX, endY, "2", paintPoint, paintText);
        }
    }

    @Override
    public void drawSampleLkYZ(Canvas canvas, TrajectVariableModel model) {
        if (null != canvas) {
            float startX = (float) (model.getWidth() * 0.824);
            float startY = (float) (model.getHeight() * 0.7);
            float endY = (float) (model.getHeight() * 0.472);
            paintLKSL.setStrokeWidth((float) (model.getWidth() * 0.039));
            Path path = new Path();
            path.moveTo(startX, startY);
            path.lineTo(startX, endY);
            path.quadTo(startX, endY - (float) (model.getHeight() * 0.051), startX + (float) (model.getWidth() * 0.039), endY - (float) (model.getHeight() * 0.051));
            path.lineTo(startX + (float) (model.getWidth() * 0.078), endY - (float) (model.getHeight() * 0.051));
            canvas.drawPath(path, paintLKSL);
            drawArrow(canvas, startX + (float) (model.getWidth() * 0.078), endY - (float) (model.getHeight() * 0.118), startX + (float) (model.getWidth() * 0.078), endY + (float) (model.getHeight() * 0.017), startX + (float) (model.getWidth() * 0.117), endY - (float) (model.getWidth() * 0.039), paintJt);
            drawGdPoint(canvas, model.getWidth(), startX, startY, "1", paintPoint, paintText);
            drawGdPoint(canvas, model.getWidth(), startX, endY - (float) (model.getHeight() * 0.051), "2", paintPoint, paintText);
        }
    }

    @Override
    public void drawSampleLkZZ(Canvas canvas, TrajectVariableModel model) {
        if (null != canvas) {
            float startX = (float) (model.getWidth() * 0.922);
            float startY = (float) (model.getHeight() * 0.7);
            float endY = (float) (model.getHeight() * 0.472);
            float strokeWidth = (float) (model.getWidth() * 0.039);
            paintLKSL.setStrokeWidth(strokeWidth);
            Path path = new Path();
            path.moveTo(startX, startY);
            path.lineTo(startX, endY);
            path.quadTo(startX, endY - strokeWidth, startX - strokeWidth, endY - strokeWidth);
            path.lineTo(startX - (float) (model.getWidth() * 0.078), endY - strokeWidth);
            canvas.drawPath(path, paintLKSL);
            drawArrow(canvas, startX - (float) (model.getWidth() * 0.078), endY - (float) (model.getWidth() * 0.091), startX - (float) (model.getWidth() * 0.078), endY + (float) (model.getWidth() * 0.013), startX - (float) (model.getWidth() * 0.117), endY - (float) (model.getWidth() * 0.039), paintJt);
            drawGdPoint(canvas, model.getWidth(), startX, startY, "1", paintPoint, paintText);
            drawGdPoint(canvas, model.getWidth(), startX, endY - strokeWidth, "2", paintPoint, paintText);
        }
    }

    @Override
    public void drawSampleLkDT(Canvas canvas, TrajectVariableModel model) {
        if (null != canvas) {
            float startX = (float) (model.getWidth() * 0.922);
            float startY = (float) (model.getHeight() * 0.7);
            float endY = (float) (model.getHeight() * 0.472);
            float strokeWidth = (float) (model.getWidth() * 0.039);
            paintLKSL.setStrokeWidth(strokeWidth);
            Path path = new Path();
            path.moveTo(startX, startY);
            path.lineTo(startX, endY);
            path.quadTo(startX, endY - strokeWidth, startX - strokeWidth, endY - strokeWidth);
            path.lineTo(startX - (float) (model.getWidth() * 0.052), endY - strokeWidth);
            path.quadTo(startX - (float) (model.getWidth() * 0.091), endY - strokeWidth, startX - (float) (model.getWidth() * 0.091), endY);
            path.lineTo(startX - (float) (model.getWidth() * 0.091), endY + (float) (model.getHeight() * 0.042));
            canvas.drawPath(path, paintLKSL);
            drawArrow(canvas, startX - (float) (model.getWidth() * 0.143), endY + (float) (model.getHeight() * 0.042), startX - (float) (model.getWidth() * 0.039), endY + (float) (model.getHeight() * 0.042), startX - (float) (model.getWidth() * 0.091), endY + (float) (model.getHeight() * 0.042) + (float) (model.getWidth() * 0.039), paintJt);
            drawGdPoint(canvas, model.getWidth(), startX, startY, "1", paintPoint, paintText);
            drawGdPoint(canvas, model.getWidth(), startX, endY - strokeWidth, "2", paintPoint, paintText);
        }
    }

    @Override
    public void drawSampleLkZXZZ(Canvas canvas, TrajectVariableModel model) {
        if (null != canvas) {
            float startX = (float) (model.getWidth() * 0.922);
            float startY = (float) (model.getHeight() * 0.7);
            float endY = (float) (model.getHeight() * 0.438);
            float centerY = (startY + endY) / 2;
            float strokeWidth = (float) (model.getWidth() * 0.039);
            paintLKSL.setStrokeWidth(strokeWidth);
            Path path = new Path();
            path.moveTo(startX, startY);
            path.lineTo(startX, endY);
            canvas.drawPath(path, paintLKSL);
            path.reset();
            path.moveTo(startX, centerY + strokeWidth);
            path.quadTo(startX, centerY, startX - strokeWidth, centerY);
            path.lineTo(startX - (float) (model.getWidth() * 0.091), centerY);
            canvas.drawPath(path, paintLKSL);
            drawArrow(canvas, startX - (float) (model.getWidth() * 0.052), endY, startX + (float) (model.getWidth() * 0.052), endY, startX, endY - (float) (model.getWidth() * 0.039), paintJt);
            drawArrow(canvas, startX - (float) (model.getWidth() * 0.091), centerY - (float) (model.getWidth() * 0.052), startX - (float) (model.getWidth() * 0.091), centerY + (float) (model.getWidth() * 0.052), startX - (float) (model.getWidth() * 0.13), centerY, paintJt);
            drawGdPoint(canvas, model.getWidth(), startX, startY, "1", paintPoint, paintText);
            drawGdPoint(canvas, model.getWidth(), startX, endY, "2", paintPoint, paintText);
        }
    }

    @Override
    public void drawSampleLkZXYZ(Canvas canvas, TrajectVariableModel model) {
        if (null != canvas) {
            float startX = (float) (model.getWidth() * 0.844);
            float startY = (float) (model.getHeight() * 0.7);
            float endY = (float) (model.getHeight() * 0.438);
            float centerY = (startY + endY) / 2;
            float strokeWidth = (float) (model.getWidth() * 0.039);
            paintLKSL.setStrokeWidth(strokeWidth);
            Path path = new Path();
            path.moveTo(startX, startY);
            path.lineTo(startX, endY);
            canvas.drawPath(path, paintLKSL);
            path.reset();
            path.moveTo(startX, centerY + strokeWidth);
            path.quadTo(startX, centerY, startX + strokeWidth, centerY);
            path.lineTo(startX + (float) (model.getWidth() * 0.091), centerY);
            canvas.drawPath(path, paintLKSL);
            drawArrow(canvas, startX - (float) (model.getWidth() * 0.052), endY, startX + (float) (model.getWidth() * 0.052), endY, startX, endY - (float) (model.getWidth() * 0.039), paintJt);
            drawArrow(canvas, startX + (float) (model.getWidth() * 0.091), centerY - (float) (model.getWidth() * 0.052), startX + (float) (model.getWidth() * 0.091), centerY + (float) (model.getWidth() * 0.052), startX + (float) (model.getWidth() * 0.13), centerY, paintJt);
            drawGdPoint(canvas, model.getWidth(), startX, startY, "1", paintPoint, paintText);
            drawGdPoint(canvas, model.getWidth(), startX, endY, "2", paintPoint, paintText);
        }
    }

    @Override
    public void drawSampleLkZXDT(Canvas canvas, TrajectVariableModel model) {
        if (null != canvas) {
            float startX = (float) (model.getWidth() * 0.92);
            float startY = (float) (model.getHeight() * 0.7);
            float endY = (float) (model.getHeight() * 0.438);
            float centerY = (startY + endY) * 0.48f;
            float strokeWidth = (float) (model.getWidth() * 0.039);
            paintLKSL.setStrokeWidth(strokeWidth);
            Path path = new Path();
            path.moveTo(startX, startY);
            path.lineTo(startX, endY);
            canvas.drawPath(path, paintLKSL);
            path.reset();
            path.moveTo(startX, centerY + strokeWidth);
            path.quadTo(startX, centerY, startX - strokeWidth, centerY);
            path.lineTo(startX - strokeWidth, centerY);
            path.quadTo(startX - (float) (model.getWidth() * 0.078), centerY, startX - (float) (model.getWidth() * 0.078), centerY + strokeWidth);
            path.lineTo(startX - (float) (model.getWidth() * 0.078), startY - (float) (model.getWidth() * 0.039));
            canvas.drawPath(path, paintLKSL);
            drawArrow(canvas, startX - (float) (model.getWidth() * 0.052), endY, startX + (float) (model.getWidth() * 0.052), endY, startX, endY - (float) (model.getWidth() * 0.039), paintJt);
            drawArrow(canvas, startX - (float) (model.getWidth() * 0.13), startY - (float) (model.getWidth() * 0.039), startX - (float) (model.getWidth() * 0.026), startY - (float) (model.getWidth() * 0.039), startX - (float) (model.getWidth() * 0.078), startY, paintJt);
            drawGdPoint(canvas, model.getWidth(), startX, startY, "1", paintPoint, paintText);
            drawGdPoint(canvas, model.getWidth(), startX, endY, "2", paintPoint, paintText);
        }
    }

    @Override
    public void drawSampleLkZZDT(Canvas canvas, TrajectVariableModel model) {
        if (null != canvas) {
            float startX = (float) (model.getWidth() * 0.948);
            float startY = (float) (model.getHeight() * 0.7);
            float endY = (float) (model.getHeight() * 0.472);
            float strokeWidth = (float) (model.getWidth() * 0.039);
            paintLKSL.setStrokeWidth(strokeWidth);
            Path path = new Path();
            path.moveTo(startX, startY);
            path.lineTo(startX, endY + strokeWidth);
            path.quadTo(startX, endY, startX - strokeWidth, endY);
            path.lineTo(startX - (float) (model.getWidth() * 0.117), endY);
            canvas.drawPath(path, paintLKSL);
            path.reset();
            path.moveTo(startX - strokeWidth, endY);
            path.quadTo(startX - (float) (model.getWidth() * 0.078), endY, startX - (float) (model.getWidth() * 0.078), endY + strokeWidth);
            path.lineTo(startX - (float) (model.getWidth() * 0.078), startY - (float) (model.getWidth() * 0.065));
            canvas.drawPath(path, paintLKSL);
            drawArrow(canvas, startX - (float) (model.getWidth() * 0.117), endY - (float) (model.getWidth() * 0.052), startX - (float) (model.getWidth() * 0.117), endY + (float) (model.getWidth() * 0.052), startX - (float) (model.getWidth() * 0.156), endY, paintJt);
            drawArrow(canvas, startX - (float) (model.getWidth() * 0.13), startY - (float) (model.getWidth() * 0.065), startX - (float) (model.getWidth() * 0.026), startY - (float) (model.getWidth() * 0.065), startX - (float) (model.getWidth() * 0.078), startY - (float) (model.getWidth() * 0.026), paintJt);
            drawGdPoint(canvas, model.getWidth(), startX, startY, "1", paintPoint, paintText);
            drawGdPoint(canvas, model.getWidth(), startX, endY, "2", paintPoint, paintText);
        }
    }

    @Override
    public void drawSampleLkZXZZDT(Canvas canvas, TrajectVariableModel model) {
        if (null != canvas) {
            float startX = (float) (model.getWidth() * 0.935);
            float startY = (float) (model.getHeight() * 0.713);
            float endY = (float) (model.getHeight() * 0.422);
            float centerY = (startY + endY) * 0.47f;
            float strokeWidth = (float) (model.getWidth() * 0.039);
            paintLKSL.setStrokeWidth(strokeWidth);
            Path path = new Path();
            path.moveTo(startX, startY);
            path.lineTo(startX, endY);
            canvas.drawPath(path, paintLKSL);
            path.reset();
            path.moveTo(startX, centerY + strokeWidth);
            path.quadTo(startX, centerY, startX - strokeWidth, centerY);
            path.lineTo(startX - (float) (model.getWidth() * 0.104), centerY);
            canvas.drawPath(path, paintLKSL);
            path.reset();
            path.moveTo(startX - strokeWidth, centerY);
            path.quadTo(startX - (float) (model.getWidth() * 0.078), centerY, startX - (float) (model.getWidth() * 0.078), centerY + strokeWidth);
            path.lineTo(startX - (float) (model.getWidth() * 0.078), startY - (float) (model.getWidth() * 0.039));
            canvas.drawPath(path, paintLKSL);
            drawArrow(canvas, startX - (float) (model.getWidth() * 0.052), endY, startX + (float) (model.getWidth() * 0.052), endY, startX, endY - (float) (model.getWidth() * 0.039), paintJt);
            drawArrow(canvas, startX - (float) (model.getWidth() * 0.104), centerY - (float) (model.getWidth() * 0.052), startX - (float) (model.getWidth() * 0.104), centerY + (float) (model.getWidth() * 0.052), startX - (float) (model.getWidth() * 0.143), centerY, paintJt);
            drawArrow(canvas, startX - (float) (model.getWidth() * 0.13), startY - (float) (model.getWidth() * 0.039), startX - (float) (model.getWidth() * 0.026), startY - (float) (model.getWidth() * 0.039), startX - (float) (model.getWidth() * 0.078), startY, paintJt);
            drawGdPoint(canvas, model.getWidth(), startX, startY, "1", paintPoint, paintText);
            drawGdPoint(canvas, model.getWidth(), startX, endY, "2", paintPoint, paintText);
        }
    }

    /**
     * 判断是否是当前的轨迹
     */
    private boolean isCurrentTrajectory(List<TrajectoryPointEntity> points, TrajectVariableModel model, Paint paintXX) {
        TrajectoryEntity trajectory = points.get(0).getTrajectory();
        boolean isCurrentTrajectory = false;
        if (null != model.getCurrentUpdateTrajectory() && model.getCurrentUpdateTrajectory().getId().equals(trajectory.getId())) {
            isCurrentTrajectory = true;
        }
        settingPaint(paintXX, points.get(0).getTrajectory(), model.getAccuracy(), isCurrentTrajectory);
        return isCurrentTrajectory;
    }

    /**
     * 设置面板
     *
     * @param paint
     * @param trajectory
     */
    private void settingPaint(Paint paint, TrajectoryEntity trajectory, int accuracy, boolean isCurrentTrajectory) {
        paint.setStrokeWidth(AccuracyPixelUtil.getAccuracyScale(accuracy) * trajectory.getLineWidth());
        switch (trajectory.getLineColor()) {
            case 1:
                paint.setColor(Color.WHITE);
                break;
            case 2:
                paint.setColor(Color.YELLOW);
                break;
            default:
                paint.setColor(Color.WHITE);
                break;
        }
        if (isCurrentTrajectory) paint.setColor(Color.BLUE);
    }

    /**
     * 画点
     *
     * @param canvas
     * @param tPoint      当前轨迹点位对象
     * @param notChooseBm 修改未选中： 显示的点位编码
     * @param chooseBm    修改选中：显示的点位编码
     */
    private void drawPoint(Canvas canvas, TrajectoryPointEntity tPoint, int notChooseBm, int chooseBm, boolean isCurrentTrajectory, TrajectVariableModel model) {
        //考试界面不显示点位，只在采集界面显示
        if (model.isCollectInterface()) {
            if (model.isCollect()) {
                drawPoint(canvas, tPoint.getPoint().getX(), tPoint.getPoint().getY(), chooseBm + "", model);
            } else {
                if (isCurrentTrajectory) { //当前轨迹显示轨迹点位编号
                    drawPointChoose(canvas, tPoint, chooseBm + "", model);
                } else {
                    if (model.isShowBsPoint()) {  //非当前轨迹显示地图编号
                        drawPoint(canvas, tPoint.getPoint().getX(), tPoint.getPoint().getY(), notChooseBm + "", model);
                    }
                }
            }
        }
    }

    /**
     * 绘制已选中点位
     *
     * @param canvas
     * @param trajectoryPoint
     * @param text
     */
    private void drawPointChoose(Canvas canvas, TrajectoryPointEntity trajectoryPoint, String text, TrajectVariableModel model) {
        if (null != model.getCurrentUpdatePoint() && trajectoryPoint.getId().equals(model.getCurrentUpdatePoint().getId())) {
            //区分颜色  红色
            paintPoint.setColor(Color.RED);
            if (!model.getCurrentText().equals(text)) {
                model.setCurrentText(text);
                if (null != model.getOnMapViewDragListener()) {
                    ((Activity) context).runOnUiThread(() -> model.getOnMapViewDragListener().OnMapViewDrag(model.getCurrentText()));
                }
            }
        } else {
            paintPoint.setColor(0xFFEEAA55);
        }
        if (null != canvas) {
            int x = model.getOriginX() + AccuracyPixelUtil.distanceToPixel(trajectoryPoint.getPoint().getX(), model.getAccuracy());
            int y = model.getOriginY() - AccuracyPixelUtil.distanceToPixel(trajectoryPoint.getPoint().getY(), model.getAccuracy());
            canvas.drawCircle(x, y, 12, paintPoint);
            if (text.length() == 1) {
                canvas.drawText(text, x - 6, y + 6, paintText);
            } else if (text.length() == 2) {
                canvas.drawText(text, x - 10, y + 6, paintText);
            }
        }
    }

    /**
     * 画点 根据比率动态显示
     *
     * @param canvas
     * @param cX
     * @param cY
     * @param text
     */
    private void drawPoint(Canvas canvas, float cX, float cY, String text, TrajectVariableModel model) {
        paintPoint.setColor(0xFFEEAA55);
        if (null != canvas) {
            int x = model.getOriginX() + AccuracyPixelUtil.distanceToPixel(cX, model.getAccuracy());
            int y = model.getOriginY() - AccuracyPixelUtil.distanceToPixel(cY, model.getAccuracy());
            canvas.drawCircle(x, y, 12, paintPoint);
            if (text.length() == 1) {
                canvas.drawText(text, x - 6, y + 6, paintText);
            } else if (text.length() == 2) {
                canvas.drawText(text, x - 10, y + 6, paintText);
            }
        }
    }

    /**
     * 绘制箭头
     */
    private void drawJt(Canvas canvas, PointBean onePoint, PointBean twoPoint, float height, float bottom, TrajectVariableModel model) {
        float juliX = twoPoint.getX() - onePoint.getX();// 有正负，不要取绝对值
        float juliY = twoPoint.getY() - onePoint.getY();// 有正负，不要取绝对值
        float juli = (float) Math.sqrt(Math.pow(juliX, 2) + Math.pow(juliY, 2));// 获取线段距离
        float dianX = twoPoint.getX() + (height / juli * juliX);
        float dianY = twoPoint.getY() + (height / juli * juliY);
        //终点的箭头
        Path path = new Path();
        path.moveTo(AccuracyPixelUtil.xDistanceToPixel(dianX, model.getOriginX(), model.getAccuracy()), AccuracyPixelUtil.yDistanceToPixel(dianY, model.getOriginY(), model.getAccuracy()));// 此点为三边形的起点
        path.lineTo(AccuracyPixelUtil.xDistanceToPixel(twoPoint.getX() + (bottom / juli * juliY), model.getOriginX(), model.getAccuracy()), AccuracyPixelUtil.yDistanceToPixel(twoPoint.getY() - (bottom / juli * juliX), model.getOriginY(), model.getAccuracy()));
        path.lineTo(AccuracyPixelUtil.xDistanceToPixel(twoPoint.getX() - (bottom / juli * juliY), model.getOriginX(), model.getAccuracy()), AccuracyPixelUtil.yDistanceToPixel(twoPoint.getY() + (bottom / juli * juliX), model.getOriginY(), model.getAccuracy()));
        path.close(); // 使这些点构成封闭的三边形
        canvas.drawPath(path, paintJt);
    }

    /**
     * 返回 在直线中 距离onePoint点距离点位坐标
     *
     * @param moveDistance
     * @param isMoveBl     是否是平移直线距离占比率
     * @return
     */
    private PointBean returnZxzjPoint(PointBean onePoint, PointBean twoPoint, Double moveDistance, boolean isMoveBl) {
        double distance = Math.sqrt((onePoint.getX() - twoPoint.getX()) * (onePoint.getX() - twoPoint.getX()) + (onePoint.getY() - twoPoint.getY()) * (onePoint.getY() - twoPoint.getY()));
        if (distance == 0) return onePoint;
        if (isMoveBl) {
            moveDistance = moveDistance * distance;
        }
        float x = (float) ((moveDistance * (twoPoint.getX() - onePoint.getX())) / distance + onePoint.getX());
        float y = (float) ((moveDistance * (twoPoint.getY() - onePoint.getY())) / distance + onePoint.getY());
        return new PointBean(x, y);
    }

    /**
     * 返回左右转第三个点
     *
     * @param onePoint
     * @param twoPoint
     * @return
     */
    private PointBean jtThreePoint(PointBean onePoint, PointBean twoPoint, double height, double width) {
        if (onePoint.getX() == twoPoint.getX() && onePoint.getY() == twoPoint.getY()) {
            return onePoint;
        }
        double awrad = Math.atan(width / height); // 箭头角度
        double arrowSize = Math.sqrt(width * width + height * height); // 箭头的长度
        double[] arrXY = rotateVec(twoPoint.getX() - onePoint.getX(), twoPoint.getY() - onePoint.getY(), awrad, arrowSize / 100);
        float x = (float) (twoPoint.getX() - arrXY[0]);
        float y = (float) (twoPoint.getY() - arrXY[1]);
        return new PointBean(x, y);
    }

    private double[] rotateVec(float px, float py, double ang, double newLen) {
        double mathstr[] = new double[2];
        double vx = px * Math.cos(ang) - py * Math.sin(ang);
        double vy = px * Math.sin(ang) + py * Math.cos(ang);
        double d = Math.sqrt(vx * vx + vy * vy);
        vx = vx / d * newLen;
        vy = vy / d * newLen;
        mathstr[0] = vx;
        mathstr[1] = vy;
        return mathstr;
    }

    /**
     * 画指定位置固定点位  跟比率无关
     *
     * @param text
     */
    private void drawGdPoint(Canvas canvas, int width, float cX, float cY, String text, Paint paintPoint, Paint paintText) {
        paintPoint.setColor(0xFFEEAA55);
        if (null != canvas) {
            canvas.drawCircle(cX, cY, (float) (width * 0.015), paintPoint);
            canvas.drawText(text, cX - (float) (width * 0.0075), cY + (float) (width * 0.0075), paintText);
        }
    }

    /**
     * 绘制道路标识的箭头
     */
    private void drawArrow(Canvas canvas, float x1, float y1, float x2, float y2, float x3, float y3, Paint paintJt) {
        Path path = new Path();
        path.moveTo(x1, y1);
        path.lineTo(x2, y2);
        path.lineTo(x3, y3);
        path.close();
        canvas.drawPath(path, paintJt);
    }

    /**
     * 计算相交点
     *
     * @param canvas
     * @param points
     * @param lines
     */
    private void caculateIntersectPoint(Canvas canvas, List<TrajectoryPointEntity> points, PointBean[] lines, TrajectVariableModel model) {
        if (jtsUtils.intersectsPolygon(lines, points)) {
            List<PointBean> intersectPoints = new ArrayList<>();
            for (int j = 0; j < points.size(); j++) {
                PointBean crossPoint = null;
                if (j == points.size() - 1) {
                    crossPoint = jtsUtils.getCrossPoint(lines[0], lines[1], points.get(j).getPoint(), points.get(0).getPoint());
                } else {
                    crossPoint = jtsUtils.getCrossPoint(lines[0], lines[1], points.get(j).getPoint(), points.get(j + 1).getPoint());
                }
                if (crossPoint != null) {
                    intersectPoints.add(crossPoint);
                }
            }
            if (intersectPoints.size() > 0) {
                //不为0，有可能为3个点，即首末点重合
                if (intersectPoints.size() % 2 != 0) {
                    intersectPoints.remove(0);
                }
                if (intersectPoints.size() % 2 == 0) {
                    for (int k = 0; k < intersectPoints.size() / 2; k++) {
                        canvas.drawLine(AccuracyPixelUtil.xDistanceToPixel(intersectPoints.get(k * 2).getX(), model.getOriginX(), model.getAccuracy()), AccuracyPixelUtil.yDistanceToPixel(intersectPoints.get(k * 2).getY(), model.getOriginY(), model.getAccuracy()), AccuracyPixelUtil.xDistanceToPixel(intersectPoints.get(k * 2 + 1).getX(), model.getOriginX(), model.getAccuracy()), AccuracyPixelUtil.yDistanceToPixel(intersectPoints.get(k * 2 + 1).getY(), model.getOriginY(), model.getAccuracy()), paintJtqy);
                    }
                }
            }
        }
    }

}
